package com.heima.admin.controller.v1;

import com.heima.admin.service.NewsAuthService;
import com.heima.apis.admin.NewsAuthControllerApi;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.NewsUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/news_auth")
public class NewsAuthController implements NewsAuthControllerApi {

    @Autowired
    private NewsAuthService newsAuthService;

    /**
     * 查询自媒体文章列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @Override
    public ResponseResult findNews(@RequestBody NewsAuthDto dto) {
        return newsAuthService.findNews(dto);
    }

    /**
     * 查询文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    @Override
    public ResponseResult findOne(@PathVariable("id") Integer id) {
        return newsAuthService.findOne(id);
    }

    /**
     * 文章审核成功
     *
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    @Override
    public ResponseResult authPass(@RequestBody NewsUpdate dto) {
        return newsAuthService.updateStatus(dto, true);
    }

    /**
     * 文章审核失败
     *
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    @Override
    public ResponseResult authFail(@RequestBody NewsUpdate dto) {
        return newsAuthService.updateStatus(dto, false);
    }
}
